package doh.client;

import javax.swing.table.*;
import java.util.*;
import java.awt.*;
import doh.service.*;
import doh.util.*;
import doh.entity.*;
import javax.swing.JFrame;
import javax.swing.JTabbedPane.*;
import javax.swing.JTable.*;
import javax.swing.JOptionPane;

public class MainMenuPanel extends javax.swing.JPanel {

    private UserSessionBeanRemote sessionBean;
    private TableModel model_ladder;
    private TableModel model_stats;
    private TableModel model_history;
    int gameID = 0;
    int round = 1;
    Vector gameSD = new Vector();
    String output = "";
    String winner = "";
    String throw1 = "default";
    String throw2 = "default";

    /** Creates new form MainMenuPanel */
    public MainMenuPanel(UserSessionBeanRemote sessionBean) {
        this.sessionBean = sessionBean;
        String[] ladderHeader = {"Rank", "Player ID", "ELO Rating"};
        java.util.List<LadderEntry> ladder = sessionBean.getLadder();
        int tableLength = ladder.size();
        Object[][] ladderContent = new Object[tableLength][3];
        Iterator itr = ladder.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            LadderEntry anEntry = (LadderEntry) itr.next();
            ladderContent[ii][0] = ii + 1;
            ladderContent[ii][1] = anEntry.player;
            ladderContent[ii][2] = anEntry.rating;
            ii++;
        }
        model_ladder = new javax.swing.table.DefaultTableModel(ladderContent, ladderHeader);
        String[] statsHeader = {"Player ID", "ELO Rating", "Games Played", "Win %", "Opponent %", "Rock %", "Paper %", "Scissors %"};
        java.util.List<Player> players = sessionBean.getPlayers();
        tableLength = players.size();
        Object[][] statsContent = new Object[tableLength][8];
        itr = players.iterator();
        ii = 0;
        while (itr.hasNext()) {
            Player aPlayer = (Player) itr.next();
            statsContent[ii][0] = aPlayer.get_id();
            statsContent[ii][1] = aPlayer.get_rating();
            statsContent[ii][2] = aPlayer.get_games();
            statsContent[ii][3] = aPlayer.get_wper();
            statsContent[ii][4] = aPlayer.get_oper();
            statsContent[ii][5] = aPlayer.get_rocks();
            statsContent[ii][6] = aPlayer.get_papers();
            statsContent[ii][7] = aPlayer.get_scissors();
            ii++;
        }
        model_stats = new javax.swing.table.DefaultTableModel(statsContent, statsHeader);
        initComponents();
        if (!this.sessionBean.getId().equals("referee")) {
            aPanel.setVisible(false);
            HistoryPanel.removeTabAt(4);
        }
        toggleButtons(false);
    }

    private void throwAction(int t) {
        Properties p = sessionBean.makeThrow(sessionBean.getId(), t, gameID);
        reflectChanges(p);
    }

    private String getUsername() {
        String retStr = "";
        retStr = sessionBean.getId();
        if (retStr.length() > 10) {
            retStr = retStr.substring(0, 9);
        }
        return retStr;
    }

    private int getRating() {
        return sessionBean.getRating(sessionBean.getId());
    }

    private void refreshStats() {
        String[] ladderHeader = {"Rank", "Player ID", "ELO Rating"};
        java.util.List<LadderEntry> ladder = sessionBean.getLadder();
        int tableLength = ladder.size();
        Object[][] ladderContent = new Object[tableLength][3];
        Iterator itr = ladder.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            LadderEntry anEntry = (LadderEntry) itr.next();
            ladderContent[ii][0] = ii + 1;
            ladderContent[ii][1] = anEntry.player;
            ladderContent[ii][2] = anEntry.rating;
            ii++;
        }
        model_ladder = new javax.swing.table.DefaultTableModel(ladderContent, ladderHeader);
        String[] statsHeader = {"Player ID", "ELO Rating", "Games Played", "Win %", "Opponent %", "Rock %", "Paper %", "Scissors %"};
        java.util.List<Player> players = sessionBean.getPlayers();
        tableLength = players.size();
        Object[][] statsContent = new Object[tableLength][8];
        itr = players.iterator();
        ii = 0;
        while (itr.hasNext()) {
            Player aPlayer = (Player) itr.next();
            statsContent[ii][0] = aPlayer.get_id();
            statsContent[ii][1] = aPlayer.get_rating();
            statsContent[ii][2] = aPlayer.get_games();
            statsContent[ii][3] = aPlayer.get_wper();
            statsContent[ii][4] = aPlayer.get_oper();
            statsContent[ii][5] = aPlayer.get_rocks();
            statsContent[ii][6] = aPlayer.get_papers();
            statsContent[ii][7] = aPlayer.get_scissors();
            ii++;
        }
        model_stats = new javax.swing.table.DefaultTableModel(statsContent, statsHeader);
        LadderTable.setModel(model_ladder);
        StatsTable.setModel(model_stats);
        WelcomePlayerLabel.setText("[User: " + sessionBean.getId() + "; Rating:" + sessionBean.getRating(sessionBean.getId()) + "]");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        HistoryPanel = new javax.swing.JTabbedPane();
        wholePanel = new javax.swing.JPanel();
        topPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        throwPanel1 = new javax.swing.JPanel();
        rockButton1 = new javax.swing.JButton();
        paperButton1 = new javax.swing.JButton();
        scissorButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        gameLabel1 = new javax.swing.JLabel();
        playButton1 = new javax.swing.JButton();
        gameLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        LadderTableScrollPane = new javax.swing.JScrollPane();
        LadderTable = new javax.swing.JTable() {
            public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index_col) {
                Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
                if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
                    comp.setBackground(new Color(220, 248, 255));
                } else {
                    comp.setBackground(Color.white);
                }
                return comp;
            }
        }
        ;
        jPanel3 = new javax.swing.JPanel();
        StatsTableScrollPane = new javax.swing.JScrollPane();
        StatsTable = new javax.swing.JTable() {
            public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index_col) {
                Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
                if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
                    comp.setBackground(new Color(220, 248, 255));
                } else {
                    comp.setBackground(Color.white);
                }
                return comp;
            }
        }
        ;
        jPanel1 = new javax.swing.JPanel();
        HistoryTableScrollPane = new javax.swing.JScrollPane();
        HistoryTable = new javax.swing.JTable() {
            public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index_col) {
                Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
                if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
                    comp.setBackground(new Color(220, 248, 255));
                } else {
                    comp.setBackground(Color.white);
                }
                return comp;
            }
        }
        ;
        jScrollBar1 = new javax.swing.JScrollBar();
        HistoryLabel = new javax.swing.JLabel();
        HistoryButton = new javax.swing.JButton();
        HistoryField = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        adminPanel = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        idField = new javax.swing.JTextField();
        passwordField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        aPanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        passwdField = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        userField = new javax.swing.JTextField();
        RefreshButton = new javax.swing.JButton();
        WelcomePlayerLabel = new java.awt.Label();
        WelcomeLabel = new java.awt.Label();

        setMaximumSize(new java.awt.Dimension(800, 600));
        setMinimumSize(new java.awt.Dimension(800, 600));

        jButton4.setText("Logout");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        topPanel.setBackground(new java.awt.Color(255, 255, 255));
        topPanel.setForeground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 24));
        jLabel1.setText("Searching for a game...");

        javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
        topPanel.setLayout(topPanelLayout);
        topPanelLayout.setHorizontalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addGap(224, 224, 224)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        topPanelLayout.setVerticalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        throwPanel1.setBackground(new java.awt.Color(255, 255, 255));
        throwPanel1.setAutoscrolls(true);

        rockButton1.setBackground(new java.awt.Color(255, 255, 255));
        rockButton1.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        rockButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/doh/client/rock.jpg"))); // NOI18N
        rockButton1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        rockButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rockButton1ActionPerformed(evt);
            }
        });

        paperButton1.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        paperButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/doh/client/paper.jpg"))); // NOI18N
        paperButton1.setContentAreaFilled(false);
        paperButton1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        paperButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paperButton1ActionPerformed(evt);
            }
        });

        scissorButton1.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        scissorButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/doh/client/scissor.jpg"))); // NOI18N
        scissorButton1.setContentAreaFilled(false);
        scissorButton1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        scissorButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                scissorButton1ActionPerformed(evt);
            }
        });

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jLabel3.setFont(new java.awt.Font("Lucida Grande", 0, 14));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Game Details");

        gameLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 20));
        gameLabel1.setText(" ");

        playButton1.setText("Find Game");
        playButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playButton1ActionPerformed(evt);
            }
        });

        gameLabel.setFont(new java.awt.Font("Lucida Grande", 0, 21));
        gameLabel.setText(" ");
        gameLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout throwPanel1Layout = new javax.swing.GroupLayout(throwPanel1);
        throwPanel1.setLayout(throwPanel1Layout);
        throwPanel1Layout.setHorizontalGroup(
            throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(throwPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(rockButton1)
                .addGap(45, 45, 45)
                .addGroup(throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(throwPanel1Layout.createSequentialGroup()
                        .addComponent(scissorButton1)
                        .addGap(34, 34, 34))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, throwPanel1Layout.createSequentialGroup()
                        .addComponent(gameLabel1)
                        .addGap(16, 16, 16)
                        .addGroup(throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(paperButton1)
                            .addComponent(gameLabel)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(293, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, throwPanel1Layout.createSequentialGroup()
                .addContainerGap(98, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 584, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(76, 76, 76))
            .addGroup(throwPanel1Layout.createSequentialGroup()
                .addGap(326, 326, 326)
                .addComponent(playButton1)
                .addContainerGap(349, Short.MAX_VALUE))
        );
        throwPanel1Layout.setVerticalGroup(
            throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(throwPanel1Layout.createSequentialGroup()
                .addGroup(throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(throwPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(gameLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(throwPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(playButton1)
                        .addGap(19, 19, 19)
                        .addComponent(gameLabel)))
                .addGap(18, 18, 18)
                .addGroup(throwPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rockButton1)
                    .addComponent(paperButton1)
                    .addComponent(scissorButton1))
                .addGap(38, 38, 38)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout wholePanelLayout = new javax.swing.GroupLayout(wholePanel);
        wholePanel.setLayout(wholePanelLayout);
        wholePanelLayout.setHorizontalGroup(
            wholePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 767, Short.MAX_VALUE)
            .addGroup(wholePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(wholePanelLayout.createSequentialGroup()
                    .addGap(4, 4, 4)
                    .addComponent(throwPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGap(5, 5, 5)))
        );
        wholePanelLayout.setVerticalGroup(
            wholePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 478, Short.MAX_VALUE)
            .addGroup(wholePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(wholePanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(throwPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        HistoryPanel.addTab("Find and Play a Game", wholePanel);

        jPanel4.setMaximumSize(new java.awt.Dimension(800, 600));

        LadderTable.setModel(model_ladder);
        LadderTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        LadderTableScrollPane.setViewportView(LadderTable);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .addComponent(LadderTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 717, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(LadderTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(202, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 767, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 625, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        HistoryPanel.addTab("View Ladder Rankings", jPanel2);

        StatsTable.setModel(model_stats);
        StatsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        StatsTable.setCellSelectionEnabled(false);
        StatsTable.setRowSelectionAllowed(true);
        StatsTableScrollPane.setViewportView(StatsTable);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(StatsTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(StatsTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        HistoryPanel.addTab("View Player Statistics", jPanel3);

        String[] historyHeader = {"Player 1", "P1 Rating", "Player 2", "P2 Rating", "ELO Adj.", "Winner"};
        Object [][] historyContent = new Object[0][6];
        model_history = new DefaultTableModel(historyContent, historyHeader);
        HistoryTable.setModel(model_history);
        HistoryTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        HistoryTableScrollPane.setViewportView(HistoryTable);

        HistoryLabel.setText("Player ID:");

        HistoryButton.setText("Fetch History");
        HistoryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HistoryButtonActionPerformed(evt);
            }
        });

        HistoryField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HistoryFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(HistoryTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(HistoryLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(HistoryField, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(HistoryButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(HistoryLabel)
                    .addComponent(HistoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(HistoryButton))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(HistoryTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        HistoryPanel.addTab("Player Match History", jPanel1);

        jButton1.setText("Delete user");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        adminPanel.add(jButton1);

        jButton2.setText("Change password");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        adminPanel.add(jButton2);

        idField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idFieldActionPerformed(evt);
            }
        });
        adminPanel.add(idField);
        adminPanel.add(passwordField);

        jLabel4.setText("User ID");
        adminPanel.add(jLabel4);

        jLabel5.setText("Password");
        adminPanel.add(jLabel5);

        jLabel6.setText("User ID");

        jLabel7.setText("Password");

        jButton3.setText("Delete user");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton5.setText("Change password");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout aPanelLayout = new javax.swing.GroupLayout(aPanel);
        aPanel.setLayout(aPanelLayout);
        aPanelLayout.setHorizontalGroup(
            aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(aPanelLayout.createSequentialGroup()
                        .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(passwdField)
                            .addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)))
                    .addGroup(aPanelLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5)))
                .addContainerGap())
        );
        aPanelLayout.setVerticalGroup(
            aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(22, 22, 22)
                .addGroup(aPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton5))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(560, 560, 560)
                        .addComponent(adminPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(234, 234, 234)
                        .addComponent(aPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(207, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(131, 131, 131)
                .addComponent(adminPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(aPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(155, Short.MAX_VALUE))
        );

        HistoryPanel.addTab("Administration", jPanel5);

        RefreshButton.setText("Refresh");
        RefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RefreshButtonActionPerformed(evt);
            }
        });

        WelcomePlayerLabel.setText("[User: "+getUsername()+"; Rating:"+getRating()+"]");
        WelcomeLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 12));

        WelcomeLabel.setText("Welcome to the Dance of Hands' Competitive Rock-Paper-Scissors Game System!");
        WelcomeLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 12));
        //WelcomeLabel.setForeground(Color.RED);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(307, 307, 307)
                        .addComponent(jButton4)
                        .addGap(70, 70, 70)
                        .addComponent(RefreshButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(WelcomeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 530, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(WelcomePlayerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(HistoryPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 772, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(WelcomePlayerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(WelcomeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(HistoryPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 504, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RefreshButton)
                    .addComponent(jButton4))
                .addContainerGap(15, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // shouldn't need this..
        //sessionBean.destroy();
//        System.exit(0);
        JFrame frame = (JFrame) this.getParent().getParent().getParent();
        this.setVisible(false);
        sessionBean.logout();
        frame.setContentPane(new LoginPanel(sessionBean));
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void idFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_idFieldActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * Real delete User thingy
     * @param evt
     */
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (this.sessionBean.deleteUser(userField.getText())) {
            JOptionPane.showMessageDialog(this, "User deleted.", "Success", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Bad username or user doesn't exist. "
                    + "Cannot delete the admin \"referee\" or a user that is currently in a game.", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * Real change password thingy
     * @param evt
     */
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        if (this.sessionBean.changeUserPassword(userField.getText(), passwdField.getText())) {
            JOptionPane.showMessageDialog(this, "User password changed.", "Success", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Bad username/password or user doesn't exist", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    /** 
     * Reflects the changes from the properties object
     * obtained from the session bean after a round.
     */
    void reflectChanges(Properties p) {
        refreshStats();
        jTextArea2.append(p.getProperty("throws") + "\n");
        jTextArea2.append(p.getProperty("status") + "\n");
        if (!p.getProperty("end").equals("false")) {
            if (p.getProperty("end").equals("1")) {
                if (p.getProperty("p1").equals(sessionBean.getId())) {
                    jTextArea2.append("-------------------\n" + "You won!\n" + "===========\n");
                } else {
                    jTextArea2.append("-------------------\n" + "You lost!\n" + "===========\n");
                }
            } else {
                if (p.getProperty("p2").equals(sessionBean.getId())) {
                    jTextArea2.append("-------------------\n" + "You won!\n" + "===========\n");
                } else {
                    jTextArea2.append("-------------------\n" + "You lost!\n" + "===========\n");
                }
            }
            round = 1;
            toggleButtons(false);
        } else {
            jTextArea2.append("--- Round " + round++ + " ---\n");
            togglePlayButtons(true);
        }
    }
    private void rockButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rockButton1ActionPerformed
        jTextArea2.append("You have made your selection, waiting for opponents throw.\n");
        jTextArea2.update(jTextArea2.getGraphics());
        togglePlayButtons(false);
//        System.err.println(rockButton1.isEnabled());

        new Thread(new GameFinderThread(sessionBean, 1, gameID)).start();
        System.out.println(rockButton1.isEnabled());
}//GEN-LAST:event_rockButton1ActionPerformed

    private void paperButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paperButton1ActionPerformed
        jTextArea2.append("You have made your selection, waiting for opponents throw.\n");
        jTextArea2.update(jTextArea2.getGraphics());
        togglePlayButtons(false);
        new Thread(new GameFinderThread(sessionBean, 2, gameID)).start();
}//GEN-LAST:event_paperButton1ActionPerformed

    private void scissorButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scissorButton1ActionPerformed
        jTextArea2.append("You have made your selection, waiting for opponents throw.\n");
        jTextArea2.update(jTextArea2.getGraphics());
        togglePlayButtons(false);
        new Thread(new GameFinderThread(sessionBean, 3, gameID)).start();

}//GEN-LAST:event_scissorButton1ActionPerformed

    private void playButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButton1ActionPerformed
        gameLabel.repaint();
        playButton1.setEnabled(false);
        new Thread(new MatchFinderThread(sessionBean, this)).start();
}//GEN-LAST:event_playButton1ActionPerformed

    /**
     * Game buttons (true means on, false off)
     * Find game (true means off, false means on)
     * @param setting
     */
    private void toggleButtons(boolean setting) {
        rockButton1.setEnabled(setting);
        paperButton1.setEnabled(setting);
        scissorButton1.setEnabled(setting);
        playButton1.setEnabled(!setting);
    }

    private void togglePlayButtons(boolean setting) {
        rockButton1.setEnabled(setting);
        paperButton1.setEnabled(setting);
        scissorButton1.setEnabled(setting);
    }

    private void HistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HistoryButtonActionPerformed
        String[] historyHeader = {"Player 1", "P1 Rating", "Player 2", "P2 Rating", "ELO Adj.", "Winner"};
        java.util.List<Game> history = sessionBean.getHistory(HistoryField.getText());
        int tableLength = history.size();
        Object[][] historyContent = new Object[tableLength][6];
        Iterator itr = history.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            Game aGame = (Game) itr.next();
            historyContent[ii][0] = aGame.get_p1();
            historyContent[ii][1] = aGame.get_r1();
            historyContent[ii][2] = aGame.get_p2();
            historyContent[ii][3] = aGame.get_r2();
            historyContent[ii][4] = aGame.get_adjustment();
            historyContent[ii][5] = aGame.get_winner();
            ii++;
        }
        model_history = new javax.swing.table.DefaultTableModel(historyContent, historyHeader);
        HistoryTable.setModel(model_history);
}//GEN-LAST:event_HistoryButtonActionPerformed

    private void HistoryFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HistoryFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_HistoryFieldActionPerformed

    private void RefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshButtonActionPerformed
        String[] ladderHeader = {"Rank", "Player ID", "ELO Rating"};
        java.util.List<LadderEntry> ladder = sessionBean.getLadder();
        int tableLength = ladder.size();
        Object[][] ladderContent = new Object[tableLength][3];
        Iterator itr = ladder.iterator();
        int ii = 0;
        while (itr.hasNext()) {
            LadderEntry anEntry = (LadderEntry) itr.next();
            ladderContent[ii][0] = ii + 1;
            ladderContent[ii][1] = anEntry.player;
            ladderContent[ii][2] = anEntry.rating;
            ii++;
        }
        model_ladder = new javax.swing.table.DefaultTableModel(ladderContent, ladderHeader);
        String[] statsHeader = {"Player ID", "ELO Rating", "Games Played", "Win %", "Opponent %", "Rock %", "Paper %", "Scissors %"};
        java.util.List<Player> players = sessionBean.getPlayers();
        tableLength = players.size();
        Object[][] statsContent = new Object[tableLength][8];
        itr = players.iterator();
        ii = 0;
        while (itr.hasNext()) {
            Player aPlayer = (Player) itr.next();
            statsContent[ii][0] = aPlayer.get_id();
            statsContent[ii][1] = aPlayer.get_rating();
            statsContent[ii][2] = aPlayer.get_games();
            statsContent[ii][3] = aPlayer.get_wper();
            statsContent[ii][4] = aPlayer.get_oper();
            statsContent[ii][5] = aPlayer.get_rocks();
            statsContent[ii][6] = aPlayer.get_papers();
            statsContent[ii][7] = aPlayer.get_scissors();
            ii++;
        }
        model_stats = new javax.swing.table.DefaultTableModel(statsContent, statsHeader);
        LadderTable.setModel(model_ladder);
        StatsTable.setModel(model_stats);
        WelcomePlayerLabel.setText("[User: " + sessionBean.getId() + "; Rating:" + sessionBean.getRating(sessionBean.getId()) + "]");
    }//GEN-LAST:event_RefreshButtonActionPerformed

    private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton HistoryButton;
    private javax.swing.JTextField HistoryField;
    private javax.swing.JLabel HistoryLabel;
    private javax.swing.JTabbedPane HistoryPanel;
    private javax.swing.JTable HistoryTable;
    private javax.swing.JScrollPane HistoryTableScrollPane;
    private javax.swing.JTable LadderTable;
    private javax.swing.JScrollPane LadderTableScrollPane;
    private javax.swing.JButton RefreshButton;
    private javax.swing.JTable StatsTable;
    private javax.swing.JScrollPane StatsTableScrollPane;
    private java.awt.Label WelcomeLabel;
    private java.awt.Label WelcomePlayerLabel;
    private javax.swing.JPanel aPanel;
    private javax.swing.JPanel adminPanel;
    private javax.swing.JLabel gameLabel;
    private javax.swing.JLabel gameLabel1;
    private javax.swing.JTextField idField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollBar jScrollBar1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JButton paperButton1;
    private javax.swing.JTextField passwdField;
    private javax.swing.JTextField passwordField;
    private javax.swing.JButton playButton1;
    private javax.swing.JButton rockButton1;
    private javax.swing.JButton scissorButton1;
    private javax.swing.JPanel throwPanel1;
    private javax.swing.JPanel topPanel;
    private javax.swing.JTextField userField;
    private javax.swing.JPanel wholePanel;
    // End of variables declaration//GEN-END:variables

    class GameFinderThread implements Runnable {

        private UserSessionBeanRemote sessionBean;
        private int action;
        private int gameID;

        public void run() {
            Properties p = sessionBean.makeThrow(sessionBean.getId(), action, gameID);
            reflectChanges(p);
            jTextArea2.setCaretPosition(jTextArea2.getText().length());

        }

        public GameFinderThread(UserSessionBeanRemote sessionBean, int action, int gameID) {
            this.sessionBean = sessionBean;
            this.action = action;
            this.gameID = gameID;
        }
    }

    class MatchFinderThread implements Runnable {

        private UserSessionBeanRemote sessionBean;
        private MainMenuPanel mmp;

        public void run() {
            mmp.gameID = sessionBean.matchPlayers(sessionBean.getId());
            if (mmp.gameID == -1) { // timeout reached
                jTextArea2.append("No other players looking for games right now, please try again.\n");
                jTextArea2.setCaretPosition(jTextArea2.getText().length());
                playButton1.setEnabled(true);
                return;
            } else if (mmp.gameID == -2) {
                jTextArea2.append("Your account has been removed by an administrator,"
                        + "or you are not logged in.\n");
                jTextArea2.setCaretPosition(jTextArea2.getText().length());
                playButton1.setEnabled(true);
                return;

            }
            jTextArea2.append("--- Round " + round++ + " ---\n");
            toggleButtons(true);
        }

        public MatchFinderThread(UserSessionBeanRemote sessionBean, MainMenuPanel mmp) {
            this.sessionBean = sessionBean;
            this.mmp = mmp;
        }
    }
}
